import SeedBank.Purchase
import SeedBank.Seed
import SeedBank.User
import grails.util.GrailsUtil

/**
 * Class used to bootstrap test users and seeds into the development database every time we are
 * in development mode.
 * 
 * @author Vikram Somu
 *
 */

class BootStrap {

	def init = { servletContext ->
		switch(GrailsUtil.environment){
			case "development":
				
				def admin = new User(
				firstName : "jim",
				lastName : "jack",
				login:"admin",
				password:"pass",
				confirmPassword:"pass",
				climateZone: "somewhere",
				phoneNumber: "770-123-4567",
				interests: "blah",
				role:"admin",
				email:"example@gmail.com",
				state: "WA",
				city: "seattle",
				zipCode: "30022",
				address: "123 Anywhere Street",
				country: "USA",
				gender: "M",
				dateOfBirth: new Date(),
				dateCreated: new Date(),
				lockCount: 0,
				hashedPass: " ",
				mailBox: []
				)

				def common = new User(
						firstName : "common",
						lastName : "user",
						login:"vikster93",
						password:"vikram",
						confirmPassword:"vikram",
						climateZone: "somewhere",
						phoneNumber: "770-113-4567",
						interests: "blah",
						role:"user",
						email:"rsdlf@gmail.com",
						state: "GA",
						city: "atlanta",
						zipCode: "30022",
						address: "123 Anywhere Street",
						country: "USA",
						gender: "M",
						dateOfBirth: new Date(),
						dateCreated: new Date(),
						lockCount: 0,
						hashedPass: " ",
						mailBox: []
						)

				admin.save()
				common.save()

				if(common.hasErrors()){
					println common.errors
				}

				if(admin.hasErrors()){
					println admin.errors
				}

				def seed1 = new Seed(
						commonName : "common name",
						scientificName: "plantis mantis",
						quantity: 1,
						startOfGrowingSeason : new Date(),
						endOfGrowingSeason : new Date(),
						price : 2,
						hardinessZone: 2,
						dateCreated : new Date(),
						lastUpdated : new Date(),
						specialRequirements: "idk",
						harvestingInformation: "ya",
						growingTips: "kk",
						user: admin,
						)

				def seed2 = new Seed(
						commonName : "commoner name",
						scientificName: "plantis fantis",
						quantity: 1,
						hardinessZone: 1,
						startOfGrowingSeason : new Date(),
						endOfGrowingSeason : new Date(),
						price : 5,
						dateCreated : new Date(),
						lastUpdated : new Date(),
						specialRequirements: "idk",
						harvestingInformation: "ya",
						growingTips: "kk",
						user: common,
						)

				seed1.save()
				seed2.save()

				if(seed1.hasErrors()){
					println seed1.errors
				}

				if(seed2.hasErrors()){
					println seed2.errors
				}
				
				/*
				def purchase1 = new Purchase(
					user: common,
					bought: seed1
				)
				
				purchase1.save()
				
				if(purchase1.hasErrors()){
					println purchase1.errors
				}
				*/
				
				break
				
				case "production" : 
				
				
				break
			
		}
	
		
		
		
    }
	
    def destroy = {
		
    }
}
